﻿using CommunityToolkitMvvmDemo.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace CommunityToolkitMvvmDemo.Servers
{
    class XmlDataService : IDataService
    {
        public List<Menu> GetAllData()
        {
            List<Menu> menuList = new List<Menu>();

            string xmlFileName = System.IO.Path.Combine(Environment.CurrentDirectory, @"Assets\Files\Menu.xml");
            XDocument xDoc = XDocument.Load(xmlFileName);
            var menus = xDoc.Descendants("Menu");
            foreach (var d in menus)
            {
                Menu m = new Menu();
                m.Name = d.Element("Name").Value;
                m.Category = d.Element("Category").Value;
                m.Comment = d.Element("Comment").Value;
                m.Score = double.Parse(d.Element("Score").Value);
                menuList.Add(m);
            }

            return menuList;
        }

        void IDataService.PlaceOrder(List<string> nameList)
        {
            System.IO.File.WriteAllLines(@"D:\Project\wpf-project\CommunityToolkitMvvmDemo\bin\Debug\net8.0-windows\Assets\Files\orders.txt", nameList.ToArray());
        }
    }
}
